{extend name="../../admin/view/main"}

{block name='content'}

<style>
    textarea {
        width: 100%;
        height: 100px;
        padding: 10px;
        border: 1px solid #ccc;
        box-sizing: border-box;
    }

</style>
<form action="{:sysuri()}" class="layui-card layui-form" data-auto="true" method="post">
    <div class="layui-card-body">


        <label class="layui-form-item relative block">
            <span class="help-label"><b>贷款名称</b></span>
            <input class="layui-input" name="loans_name" placeholder="请输入贷款名称" required value='{$vo.loans_name|default=""}'>
        </label>



        <div class="layui-form-item label-required-prev">
            <span class="help-label"><b>机构类型</b></span>
            <select class="layui-select" lay-filter="institution_type" required name="institution_type" lay-search>
                <option value="">-- 请选择 --</option>
                {if !empty($vo.institution_type)}
                {foreach $institutions_type_list as $k=>$v}
                <!-- {if $v.id eq $vo.institution_type} -->
                <option selected value="{$v.id}">{$v.institutions_type_name|default="无"}</option>
                <!-- {else} -->
                <option value="{$v.id}">{$v.institutions_type_name|default="无"}</option>
                <!-- {/if} -->
                {/foreach}
                {else}
                {foreach $institutions_type_list as $k=>$v}
                <option value="{$v.id}">{$v.institutions_type_name|default="无"} </option>
                {/foreach}
                {/if}
            </select>
        </div>


        <label class="layui-form-item relative block">
            <span class="help-label"><b>贷款期限开始</b></span>
            <input class="layui-input" name="loan_term_start" type="number" placeholder="请输入贷款期限开始" required value='{$vo.loan_term_start|default=""}'>
        </label>

        <label class="layui-form-item relative block">
            <span class="help-label"><b>贷款期限结束</b></span>
            <input class="layui-input" name="loan_term_end" type="number" placeholder="请输入贷款期限结束" required value='{$vo.loan_term_end|default=""}'>
        </label>


        <div class="layui-col-xs12 label-required-prev" style="margin-bottom:10px;">
            <span class="help-label"><b>担保方式</b></span>
            <span class="color-desc margin-left-5"></span>
            <div id="peipeiList1" class="xm-select-demo" ></div>
            <input type="hidden" name="method" id="method" value="{$vo.method|default=''}">
        </div>

        <div class="layui-form-item label-required-prev">
            <span class="help-label"><b>还款方式</b></span>
            <select class="layui-select" lay-filter="repayment" required name="repayment" lay-search>
                <option value="">-- 请选择 --</option>
                {if !empty($vo.repayment)}
                {foreach $repayment_list as $k=>$v}
                <!-- {if $v.id eq $vo.repayment} -->
                <option selected value="{$v.id}">{$v.repayment_name|default="无"}</option>
                <!-- {else} -->
                <option value="{$v.id}">{$v.repayment_name|default="无"}</option>
                <!-- {/if} -->
                {/foreach}
                {else}
                {foreach $repayment_list as $k=>$v}
                <option value="{$v.id}">{$v.repayment_name|default="无"} </option>
                {/foreach}
                {/if}
            </select>
        </div>


        <label class="layui-form-item relative block">
            <span class="help-label"><b>额度区间开始</b></span>
            <input class="layui-input" name="quota_start" type="number" placeholder="请输入额度区间开始" required value='{$vo.quota_start|default=""}'>
        </label>

        <label class="layui-form-item relative block">
            <span class="help-label"><b>额度区间结束</b></span>
            <input class="layui-input" name="quota_end" type="number" placeholder="请输入额度区间结束" required value='{$vo.quota_end|default=""}'>
        </label>


        <label class="layui-form-item relative block">
            <span class="help-label"><b>贷款年单利开始</b></span>
            <input class="layui-input" name="simple_interest_start" placeholder="请输入贷款年单利开始" required value='{$vo.simple_interest_start|default=""}'>
        </label>

        <label class="layui-form-item relative block">
            <span class="help-label"><b>贷款年单利结束</b></span>
            <input class="layui-input" name="simple_interest_end" placeholder="请输入贷款年单利结束" required value='{$vo.simple_interest_end|default=""}'>
        </label>


        <div class="layui-form-item label-required-prev">
            <span class="help-label"><b>银行机构</b></span>
            <select class="layui-select" lay-filter="institution" required name="institution" lay-search>
                <option value="">-- 请选择 --</option>
                {if !empty($vo.institution)}
                {foreach $institution_list as $k=>$v}
                <!-- {if $v.id eq $vo.institution} -->
                <option selected value="{$v.id}">{$v.institutions_name|default="无"}</option>
                <!-- {else} -->
                <option value="{$v.id}">{$v.institutions_name|default="无"}</option>
                <!-- {/if} -->
                {/foreach}
                {else}
                {foreach $institution_list as $k=>$v}
                <option value="{$v.id}">{$v.institutions_name|default="无"} </option>
                {/foreach}
                {/if}
            </select>
        </div>


        <div class="layui-form-item label-required-prev">
            <span class="help-label"><b>特点</b></span>
            <div class="relative block">
                <textarea class="" name="characteristics" placeholder="请输入特点">{$vo.characteristics|default=''}</textarea>
            </div>
        </div>


        <div class="layui-form-item label-required-prev">
            <span class="help-label"><b>申请条件</b></span>
            <div class="relative block">
                <textarea class="layui-hide" name="conditions" placeholder="请输入申请条件">{$vo.conditions|default=''}</textarea>
            </div>
        </div>


        <div class="layui-col-xs12 label-required-prev" style="margin-bottom:10px;">
            <span class="help-label"><b>服务流程</b></span>
            <span class="color-desc margin-left-5"></span>
            <div id="peipeiList2" class="xm-select-demo" ></div>
            <input type="hidden" name="services_process" id="services_process" value="{$vo.services_process|default=''}">
        </div>


        <div class="hr-line-dashed"></div>
        {notempty name='vo.id'}<input name='id' type='hidden' value='{$vo.id}'>{/notempty}

        <div class="layui-form-item text-center">
            <button class="layui-btn" type="submit">保存数据</button>
            <button class="layui-btn layui-btn-danger" data-history-back data-confirm="确定要取消编辑吗？" type='button'>取消编辑</button>
        </div>
    </div>

</form>

<script>
    require(['ckeditor'], function () {
        window.createEditor('[name=conditions]', {height: 350})
    });
</script>

<script>
    $(function () {
        getMethodList();
        getServicesProcessList();
    });
    function getMethodList() {
        layui.use('xmSelect', function () {
            $.ajax({
                type: 'get',
                url: "{:url('getMethodList')}",
                data: "",
                dataType: "json",
                success: function (res) {
                    if (res.code) {
                        console.log(res);
                        var datas = [];
                        res.data.forEach(function (item) {
                            var uuid = "{$vo.method|default=''}".split(',');
                            if (uuid.length && uuid.findIndex(it => it == item.id) != -1) {
                                datas.push({name: item.method_name, value: item.id, selected: true});

                            } else {
                                datas.push({name: item.method_name, value: item.id});
                            }
                        });
                        xmSelect.render({
                            el: '#peipeiList1',
                            tips: '请选择担保方式',//选项提示文字
                            data: datas,
                            on: function (data) {
                                var selectArr = data.arr;
                                var seachArr = [];
                                for (var j = 0; j < selectArr.length; j++) {
                                    seachArr.push(selectArr[j].value)
                                }
                                $("#method").val(seachArr.toString());
                            }
                        })
                    } else {
                        console.log(res.info);
                    }
                },
                error: function (err) {
                    console.log(err)
                }
            });
        });
    }


    function getServicesProcessList() {
        layui.use('xmSelect', function () {
            $.ajax({
                type: 'get',
                url: "{:url('getServicesProcessList')}",
                data: "",
                dataType: "json",
                success: function (res) {
                    if (res.code) {
                        console.log(res);
                        var datas = [];
                        res.data.forEach(function (item) {
                            var uuid = "{$vo.services_process|default=''}".split(',');
                            if (uuid.length && uuid.findIndex(it => it == item.id) != -1) {
                                datas.push({name: item.process_name, value: item.id, selected: true});

                            } else {
                                datas.push({name: item.process_name, value: item.id});
                            }
                        });
                        xmSelect.render({
                            el: '#peipeiList2',
                            tips: '请选择服务流程',//选项提示文字
                            data: datas,
                            on: function (data) {
                                var selectArr = data.arr;
                                var seachArr = [];
                                for (var j = 0; j < selectArr.length; j++) {
                                    seachArr.push(selectArr[j].value)
                                }
                                $("#services_process").val(seachArr.toString());
                            }
                        })
                    } else {
                        console.log(res.info);
                    }
                },
                error: function (err) {
                    console.log(err)
                }
            });
        });
    }
</script>
{/block}
